import 'package:flutter/material.dart';
import 'photo_backup_page.dart';

class BackupPage extends StatelessWidget {
  const BackupPage({Key? key}) : super(key: key);

  Widget _buildCardItem(BuildContext context, {required Widget child}) {
    final theme = Theme.of(context);
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 2.0),
      decoration: BoxDecoration(
        color: theme.cardColor,
        borderRadius: BorderRadius.circular(10),
        boxShadow: [
          BoxShadow(
            color: theme.shadowColor.withOpacity(0.03),
            blurRadius: 1,
            offset: const Offset(0, 1),
          ),
        ],
      ),
      child: child,
    );
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final colorScheme = theme.colorScheme;

    return Scaffold(
      backgroundColor:
          theme.brightness == Brightness.light
              ? colorScheme.surface.withOpacity(0.95)
              : colorScheme.surface.withOpacity(0.2),
      appBar: AppBar(
        title: const Text('更多设置'),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back),
          onPressed: () => Navigator.of(context).pop(),
        ),
        elevation: 0,
        backgroundColor: colorScheme.surface,
        foregroundColor: colorScheme.onSurface,
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            // 顶部信息区
            _buildInfoSection(context),

            const SizedBox(height: 10),

            // 相册备份选项
            _buildCardItem(
              context,
              child: _buildBackupItem(
                context,
                icon: Icons.photo_library,
                iconColor: colorScheme.primary,
                title: '相册备份',
                isEnabled: false,
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const PhotoBackupPage(),
                    ),
                  );
                },
              ),
            ),

            const SizedBox(height: 10),

            // 手机文件备份区域
            _buildSectionTitle(context, '手机文件备份'),
            _buildCardItem(
              context,
              child: Column(
                children: [
                  _buildBackupItem(
                    context,
                    icon: Icons.insert_drive_file,
                    iconColor: colorScheme.primary,
                    title: '文档备份',
                    isEnabled: false,
                  ),
                  const Divider(height: 1, indent: 72),
                  _buildBackupItem(
                    context,
                    icon: Icons.chat_bubble,
                    iconColor: colorScheme.secondary,
                    title: '微信文件备份',
                    isEnabled: false,
                  ),
                  const Divider(height: 1, indent: 72),
                  _buildBackupItem(
                    context,
                    icon: Icons.folder,
                    iconColor: colorScheme.tertiary,
                    title: '文件夹备份',
                    isEnabled: false,
                    isVip: true,
                  ),
                  const Divider(height: 1, indent: 72),
                  _buildBackupItem(
                    context,
                    icon: Icons.audiotrack,
                    iconColor: colorScheme.primary,
                    title: '音频备份',
                    isEnabled: false,
                  ),
                ],
              ),
            ),

            const SizedBox(height: 10),

            // 手机数据备份区域
            _buildSectionTitle(context, '手机数据备份'),
            _buildCardItem(
              context,
              child: Column(
                children: [
                  _buildBackupItem(
                    context,
                    icon: Icons.contacts,
                    iconColor: colorScheme.secondary,
                    title: '通讯录备份',
                    isEnabled: false,
                  ),
                  const Divider(height: 1, indent: 72),
                  _buildBackupItem(
                    context,
                    icon: Icons.sms,
                    iconColor: colorScheme.primary,
                    title: '短信备份',
                    isEnabled: false,
                  ),
                  const Divider(height: 1, indent: 72),
                  _buildBackupItem(
                    context,
                    icon: Icons.call,
                    iconColor: colorScheme.tertiary,
                    title: '通话记录',
                    isEnabled: false,
                  ),
                  const Divider(height: 1, indent: 72),
                  _buildBackupItem(
                    context,
                    icon: Icons.apps,
                    iconColor: colorScheme.secondary,
                    title: '应用备份',
                    isEnabled: false,
                  ),
                ],
              ),
            ),

            // 自动备份设置
            const SizedBox(height: 10),
            _buildCardItem(
              context,
              child: InkWell(
                onTap: () {
                  // TODO: 实现自动备份设置
                },
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Row(
                    children: [
                      Text('自动备份更多设置', style: theme.textTheme.titleMedium),
                      const Spacer(),
                      Icon(
                        Icons.chevron_right,
                        color: theme.textTheme.bodySmall?.color,
                        size: 20,
                      ),
                    ],
                  ),
                ),
              ),
            ),

            const SizedBox(height: 20),
          ],
        ),
      ),
    );
  }

  Widget _buildInfoSection(BuildContext context) {
    final theme = Theme.of(context);
    final colorScheme = theme.colorScheme;

    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(20.0),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [
            colorScheme.primary.withOpacity(0.1),
            colorScheme.secondary.withOpacity(0.1),
          ],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
      ),
      child: Column(
        children: [
          Icon(Icons.backup, size: 80, color: colorScheme.primary),
          const SizedBox(height: 16),
          Text('珍贵文件数据，安全备份不怕丢失', style: theme.textTheme.titleMedium),
          const SizedBox(height: 8),
          Text(
            '多重加密备份，保护你的隐私',
            style: theme.textTheme.bodyMedium?.copyWith(
              color: theme.textTheme.bodySmall?.color,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSectionTitle(BuildContext context, String title) {
    final theme = Theme.of(context);
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
      child: Row(
        children: [
          Text(
            title,
            style: theme.textTheme.titleMedium?.copyWith(
              color: theme.textTheme.bodySmall?.color,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildBackupItem(
    BuildContext context, {
    required IconData icon,
    required Color iconColor,
    required String title,
    required bool isEnabled,
    bool isVip = false,
    VoidCallback? onTap,
  }) {
    final theme = Theme.of(context);
    final colorScheme = theme.colorScheme;

    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
          child: Row(
            children: [
              Container(
                padding: const EdgeInsets.all(8.0),
                decoration: BoxDecoration(
                  color: iconColor.withOpacity(0.1),
                  borderRadius: BorderRadius.circular(8.0),
                ),
                child: Icon(icon, color: iconColor, size: 24),
              ),
              const SizedBox(width: 16),
              Text(title, style: theme.textTheme.titleMedium),
              if (isVip) ...[
                const SizedBox(width: 8),
                Container(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 6,
                    vertical: 2,
                  ),
                  decoration: BoxDecoration(
                    color: colorScheme.primary,
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: Text(
                    'SVIP',
                    style: theme.textTheme.labelSmall?.copyWith(
                      color: colorScheme.onPrimary,
                    ),
                  ),
                ),
              ],
              const Spacer(),
              Text(
                isEnabled ? '已开启' : '未开启',
                style: TextStyle(
                  color:
                      isEnabled
                          ? colorScheme.primary
                          : theme.textTheme.bodySmall?.color,
                  fontSize: 14,
                ),
              ),
              const SizedBox(width: 8),
              Icon(
                Icons.chevron_right,
                color: theme.textTheme.bodySmall?.color,
                size: 20,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
